home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / SAT / SATminimal ƒ / sMySprite.p < prev   
Encoding:
Text File  |  1994-07-26  |  1.4 KB  |  59 lines  |  [TEXT/PJMM]

  1. {The sprite unit for SATminimal}
  2.  
  3. unit sMySprite;
  4.  
  5. interface
  6.     uses
  7.         SAT;
  8.     var
  9.         theSound: Handle;
  10.         faces: array[0..5] of FacePtr;
  11.  
  12.     procedure InitMySprite;
  13.     procedure SetupMySprite (me: SpritePtr);
  14.     procedure HandleMySprite (me: SpritePtr);
  15.  
  16. implementation
  17.  
  18. {Initialization of variables used by the sprite unit}
  19.     procedure InitMySprite;
  20.         var
  21.             i: integer;
  22.     begin
  23. {Preload the sound}
  24.         theSound := SATGetSound(128);
  25. {Preload all icons used by the sprites - 6 of them}
  26.         for i := 0 to 5 do
  27.             faces[i] := GetFace(128 + i);
  28.     end;
  29.  
  30. {Initialize a new sprite}
  31.     procedure SetupMySprite (me: SpritePtr);
  32.     begin
  33.         me^.mode := 0;                    {Pick a valid face number}
  34.         me^.speed.h := 2;                    {Set the speed - only horizontal is used here }
  35.         me^.task := @HandleMySprite;    {Set a handling routine. MANDATORY! If nil, the sprite will self-destruct.}
  36.     end;
  37.  
  38. {Define the behaviour of a sprite}
  39.     procedure HandleMySprite (me: SpritePtr);
  40.     begin
  41. {Select a face. We use me^.mode as face counter, rotating through them.}
  42.         me^.mode := (me^.mode + 1) mod 6;
  43.         me^.face := faces[me^.mode];
  44.  
  45. {Move}
  46.         me^.position.h := me^.position.h + me^.speed.h; {Add the speed - horizontal only}
  47.         if me^.position.h > gSAT.offSizeH - 16 then {Turn back if at the right border}
  48.             begin
  49.                 me^.speed.h := -2;
  50.                 SATSoundPlay(theSound, 1, true);
  51.             end;
  52.         if me^.position.h < -16 then {Turn back if at the left border}
  53.             begin
  54.                 me^.speed.h := 2;
  55.                 SATSoundPlay(theSound, 1, true);
  56.             end;
  57.     end;
  58.  
  59. end.